import { Injectable } from '@angular/core';
import { ApiService } from '@core/net/api.service';
import { IHttpRes } from '@core/net/HttpResponse';
import { IGrid, IGridHouseholdInfo } from '@model/grid';

@Injectable({
	providedIn: 'root'
})
export class GridService {

	constructor(
		private apiService: ApiService
	) { }

	/**
	 * 村户列表
	 * @param params 
	 * @returns 
	 */
	getHouseholdList(params): Promise<IHttpRes<{list: Array<IGridHouseholdInfo>, totalCount: number}>> {
		return this.apiService.post('/info/tdatahousehold/list', params).toPromise();
	}

	/**
	 * 根据微网格员获取村户列表
	 * @param params 
	 * @returns 
	 */
	getHouseholdListByGrider(id: string): Promise<IHttpRes<Array<{address: string, areaName:string}>>> {
		return this.apiService.get(`/info/tdatahousehold/selectByGrider/${id}`).toPromise();
	}

	/**
	 * 根据网格获取村户列表
	 * @param params 
	 * @returns 
	 */
	getHouseholdListByGridArea(areaId: string): Promise<IHttpRes<Array<any>>> {
		return this.apiService.get(`/info/tdatahousehold/selectByGridArea/${areaId}`).toPromise();
	}
	/**
	 * 根据社区获取村户列表
	 * @returns 
	 */
	getHouseholdSelectByAreae(areaId: string): Promise<IHttpRes<Array<IGridHouseholdInfo>>> {
		return this.apiService.get(`/info/tdatahousehold/selectByArea/${areaId}`).toPromise();
	}

	/**
	 * 删除村户
	 * @param id 
	 * @returns 
	 */
	deleteHousehold(id: number): Promise<IHttpRes<any>> {
		return this.apiService.post('/info/tdatahousehold/delete/' + id).toPromise();
	}


	/**
	 * 村户详情
	 * @param id 
	 * @returns 
	 */
	getHouseholdInfo(id: number): Promise<IHttpRes<any>> {
		return this.apiService.get('/info/tdatahousehold/info/' + id).toPromise();
	}
	/**
	 * 新增村户
	 * @param body 
	 * @returns 
	 */
	saveHousehold(body): Promise<IHttpRes<any>> {
		return this.apiService.post('/info/tdatahousehold/save', body).toPromise();
	}
	/**
	 * 根据网格获取所属栋
	 * @param id 
	 * @returns 
	 */
	getInfoForDong(id): Promise<IHttpRes<any>> {
		return this.apiService.get(`/info/tdatagridarea/infoForDong/${id}`).toPromise();
	}









	/**
	 * 网格员列表
	 * @param params 
	 * @returns 
	 */
	 getGriderList(params): Promise<IHttpRes<{list: Array<IGrid>, totalCount: number}>> {
		return this.apiService.post('/info/tdatagrider/list', params).toPromise();
	}

	/**
	 * 删除网格员
	 * @param id 
	 * @returns 
	 */
	deleteGrider(id: number): Promise<IHttpRes<any>> {
		return this.apiService.post('/info/tdatagrider/delete/' + id).toPromise();
	}

	/**
	 * 网格员详情
	 * @param id 
	 * @returns 
	 */
	getGriderInfo(griderType: string,id: string): Promise<IHttpRes<any>> {
		return this.apiService.get(`/info/tdatagrider/info/${griderType}/${id}`).toPromise();
	}
	/**
	 * 新增网格员
	 * @param body 
	 * @returns 
	 */
	saveGrider(body): Promise<IHttpRes<any>> {
		return this.apiService.post('/info/tdatagrider/save', body).toPromise();
	}

	/**
	 * 根据网格区获取微网格员列表
	 * @param body 
	 * @returns 
	 */
	getGriderMinilist(areaId: string): Promise<IHttpRes<any>> {
		return this.apiService.post(`/info/tdatagrider/minilist/${areaId}`).toPromise();
	}
	/**
	 * 根据社区获取网格区信息
	 * @param body 
	 * @returns 
	 */
	gridAreaInfoByCommunity(areaId: string): Promise<IHttpRes<any>> {
		return this.apiService.get(`/info/tdatagridarea/infoByCommunity/${areaId}`).toPromise();
	}

	/**
	 * 根据社区获取所属栋
	 * @param body 
	 * @returns 
	 */
	getDongTree(areaId: string): Promise<IHttpRes<any>> {
		return this.apiService.get(`/info/tdataareaaddr/getDongTree/${areaId}`).toPromise();
	}

}
